/**
 * Created by Administrator on 2017/6/21.
 */

const app = require('express')();
const call = require('./call.js');
const pay = require('./pay.js');

module.exports = app;

app.get('/alert', function (req, res) {

});

app.get('/getRobot', function (req, res) {
    var result = {};
    if (!call.robot.check()) {
        result.code = 101;
        res.send(result).end();
        return false;
    }
    result.robotId = call.robot.getList(req.query.lv);
    result.code = 200;
    res.send(result).end();
});

app.get('/setBlued', function (req, res) {
    var result = {};
    if (!req.query.uid) {
        result.code = 101;
        res.send(result).end();
        return false;
    }
    if (req.query.accessToken && req.query.expire) {
        call.blued.setAccessToken(req.query.uid, req.query.accessToken, req.query.expire);
    }
    if (req.query.platform) {
        call.blued.setPlatform(req.query.uid, req.query.platform);
    }
    result.code = 200;
    res.send(result).end();
});
app.get('/getBlued', function (req, res) {
    var result = {};
    if (!req.query.uid) {
        result.code = 101;
        res.send(result).end();
        return false;
    }
    var platform = call.blued.getPlatform(req.query.uid);
    var accessToken = call.blued.getAccessToken(req.query.uid);
    result.platform = platform;
    result.accessToken = accessToken;
    result.code = 200;
    res.send(result).end();
});

app.get('/payCallback', function (req, res) {
    pay.callback(req.query);
    var result = {};
    result.code = 200;
    res.send(result).end();
});

app.get('/addGame', function (req, res) {
    call.gameLists.addGame(req.query.gameId, req.query.lv);
    var result = {};
    result.code = 200;
    res.send(result).end();
});
app.get('/delGame', function (req, res) {
    call.gameLists.delGame(req.query.gameId);
    var result = {};
    result.code = 200;
    res.send(result).end();
});
app.get('/getGameAmount', function (req, res) {
    var result = {};
    result.code = 200;
    result.amount = call.gameLists.amount();
    res.send(result).end();
});